0

I am facing a problem regarding global temporary tables in Postgres Sql. If two procedures:

  1. A() having a temporary table say temp(id, name)
  2. B() having a temporary table say temp(id, name, address)

then if the procedure A is called first and after that procedure B is called then the temp table remains with the structure i.e. temp(id, name) defined in the procedure A and vice versa and the column "address" as defined in procedure B is not found.

Please help me to find a solution???

3
  • So you want procedure-local temporary tables so that A's and B's temp tables would not be visible to the other procedure? Commented May 22, 2013 at 6:03
  • i mean to say if we make a database call for A first, then temp table is created with columns id and name. after that if we make a database call for B then the temp table defined in B is not there, it takes the temp table as defined in A with columns id and name. the column address as defined in temp table of B is not found. Commented May 22, 2013 at 6:21
  • You want the procedures to share the same temp table but the procedures need it to have different columns? Or do you want them to share it but create it (with different columns) if someone else hasn't created it already? Both seem a bit odd to me. Commented May 22, 2013 at 6:43

2 Answers 2

1

If you really need to have explicit temporary tables, just create these with a unique name.

Anyway, the common approaches would be to handle it in SQL selects without explicit temporary tables, possibly extended by using with queries (common table expressions).

Sign up to request clarification or add additional context in comments.

1 Comment

Not that I am aware of. Three alternatives are not enough :-) Describe your use case a bit further.
0

Basically you have two options.

The first is to make your tables unique so that they don't hit the same ones. This would be preferred if you are using these to store longer-term session-specific data. These could be named uniquely.

A second is that you can create, use, and drop your tables inside the same stored procedure so that stored procedure A can be generally guaranteed that relation temp does not exist when starting and the same with stored procedure B.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.