Thread: simple function index question
This:CREATE INDEX TX_QSET_DIR_MAP_PRI_URI_TYP_UKON tx_question_set_dir_mapUSING btree((CASEWHEN uri_type = 201900 then(question_set2tx_question_set ,uri_type, null)ELSE(question_set2tx_question_set ,uri_type, question_set_dir_map_key)END))TABLESPACE qsn_indx_ol;results inERROR: column "" has pseudo-type record********** Error **********ERROR: column "" has pseudo-type recordSQL state: 42P16Hopefully it is clear what I am attempting to do here. How do I make this happen?
ERROR: column "" has pseudo-type record
--
:wq
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Michael Moore
Sent: Tuesday, March 22, 2016 8:24 PM
To: postgres list <pgsql-sql@postgresql.org>
Subject: [SQL] simple function index question
This:
CREATE INDEX TX_QSET_DIR_MAP_PRI_URI_TYP_UK
ON tx_question_set_dir_map
USING btree
((
CASE
WHEN uri_type = 201900 then
(question_set2tx_question_set ,uri_type, null)
ELSE
(question_set2tx_question_set ,uri_type, question_set_dir_map_key)
END))
TABLESPACE qsn_indx_ol;
results in
ERROR: column "" has pseudo-type record
********** Error **********
ERROR: column "" has pseudo-type record
SQL state: 42P16
Hopefully it is clear what I am attempting to do here. How do I make this happen?
Try casting NULL to whatever type question_set_dirmap_key is.
Sai it is varchar, then:
……………………………………………..
WHEN uri_type = 201900 then
(question_set2tx_question_set ,uri_type, null::varchar)
……………………………………………………………….
Regards,
Igor Neyman
On Tuesday, March 22, 2016, Michael Moore <michaeljmoore@gmail.com> wrote:ERROR: column "" has pseudo-type recordJust guessing, and don't have time to verify, but you might try casting the null value in the WHEN clause to the same type as the question_set_dir_map_key column in the ELSE clause.I'd probably also try doing this with two separate indexes; this feels a bit like it might asking the one index to do too much.
--
:wq
On Tue, Mar 22, 2016 at 5:54 PM, Rosser Schwarz <rosser.schwarz@gmail.com> wrote:On Tuesday, March 22, 2016, Michael Moore <michaeljmoore@gmail.com> wrote:ERROR: column "" has pseudo-type recordJust guessing, and don't have time to verify, but you might try casting the null value in the WHEN clause to the same type as the question_set_dir_map_key column in the ELSE clause.I'd probably also try doing this with two separate indexes; this feels a bit like it might asking the one index to do too much.
CREATE INDEX TX_QSET_DIR_MAP_PRI_URI_TYP_UK
ON tx_question_set_dir_map (question_set2tx_question_set ,uri_type, null)
WHERE uri_type = 201900
TABLESPACE qsn_indx_ol;
CREATE INDEX TX_QSET_DIR_MAP_PRI_URI_TYP_2_UK
ON tx_question_set_dir_map (question_set2tx_question_set ,uri_type, question_set_dir_map_key)
WHERE uri_type != 201900
TABLESPACE qsn_indx_ol;
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Michael Moore
Sent: Wednesday, March 23, 2016 11:14 AM
To: postgres list <pgsql-sql@postgresql.org>
Subject: Re: [SQL] simple function index question
Thanks guys,
I agree that the data model is suspect. I'm trying to convert from Oracle to Postgres and changing table structures is not really an option for me. I tried casting the null, ... same problem. It does not like the undefined record type as David is saying. I will try his solution and let you know how it goes.
Interestingly a version of this:
CREATE INDEX TX_QSET_DIR_MAP_PRI_URI_TYP_UK
ON tx_question_set_dir_map
USING btree
(question_set2tx_question_set ,uri_type,
(CASE WHEN uri_type = 201900 THEN null::varchar(100)
ELSE question_set_dir_map_key END);
Worked for me. Try it if you are still interested.
Just do proper casting of null (it was varchar(100) in my case).
Regards,
Igor Neyman
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Igor Neyman
Sent: Wednesday, March 23, 2016 11:57 AM
To: Michael Moore <michaeljmoore@gmail.com>; postgres list <pgsql-sql@postgresql.org>
Subject: Re: [SQL] simple function index question
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Michael Moore
Sent: Wednesday, March 23, 2016 11:14 AM
To: postgres list <pgsql-sql@postgresql.org>
Subject: Re: [SQL] simple function index question
Thanks guys,
I agree that the data model is suspect. I'm trying to convert from Oracle to Postgres and changing table structures is not really an option for me. I tried casting the null, ... same problem. It does not like the undefined record type as David is saying. I will try his solution and let you know how it goes.
Interestingly a version of this:
CREATE INDEX TX_QSET_DIR_MAP_PRI_URI_TYP_UK
ON tx_question_set_dir_map
USING btree
(question_set2tx_question_set ,uri_type,
(CASE WHEN uri_type = 201900 THEN null::varchar(100)
ELSE question_set_dir_map_key END);
Worked for me. Try it if you are still interested.
Just do proper casting of null (it was varchar(100) in my case).
Regards,
Igor Neyman
Of course, missed “)” at the end:
CREATE INDEX TX_QSET_DIR_MAP_PRI_URI_TYP_UK
ON tx_question_set_dir_map
USING btree
(question_set2tx_question_set ,uri_type,
(CASE WHEN uri_type = 201900 THEN null::varchar(100)
ELSE question_set_dir_map_key END));
Regards,
Igor
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Michael Moore
Sent: Wednesday, March 23, 2016 11:14 AM
To: postgres list <pgsql-sql@postgresql.org>
Subject: Re: [SQL] simple function index question
Thanks guys,
I agree that the data model is suspect. I'm trying to convert from Oracle to Postgres and changing table structures is not really an option for me. I tried casting the null, ... same problem. It does not like the undefined record type as David is saying. I will try his solution and let you know how it goes.
Interestingly a version of this:
CREATE INDEX TX_QSET_DIR_MAP_PRI_URI_TYP_UK
ON tx_question_set_dir_map
USING btree
(question_set2tx_question_set ,uri_type,
(CASE WHEN uri_type = 201900 THEN null::varchar(100)
ELSE question_set_dir_map_key END);
Worked for me. Try it if you are still interested.
Just do proper casting of null (it was varchar(100) in my case).
Interestingly a version of this:
CREATE INDEX TX_QSET_DIR_MAP_PRI_URI_TYP_UK
ON tx_question_set_dir_map
USING btree
(question_set2tx_question_set ,uri_type,
(CASE WHEN uri_type = 201900 THEN null::varchar(100)
ELSE question_set_dir_map_key END);
Worked for me. Try it if you are still interested.
Just do proper casting of null (it was varchar(100) in my case).
This is a multi-column index - with the third column being an expression - as opposed to a single-column index of a composite.
David J.
________________________________________________________________________________
You are right.
But the question is whether OP needs a single_column_index_of_a_composite or multi_column_index will do.
Regards,
Igor Neyman
Interestingly a version of this:
CREATE INDEX TX_QSET_DIR_MAP_PRI_URI_TYP_UK
ON tx_question_set_dir_map
USING btree
(question_set2tx_question_set ,uri_type,
(CASE WHEN uri_type = 201900 THEN null::varchar(100)
ELSE question_set_dir_map_key END);
Worked for me. Try it if you are still interested.
Just do proper casting of null (it was varchar(100) in my case).
This is a multi-column index - with the third column being an expression - as opposed to a single-column index of a composite.
David J.
________________________________________________________________________________
You are right.
But the question is whether OP needs a single_column_index_of_a_composite or multi_column_index will do.
Regards,
Igor Neyman